<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}区块链交易行为特征分析与可视化系统{% endblock %}</title>
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome 图标 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
    <!-- Chart.js -->
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <style>
        body {
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }
        .content {
            flex: 1;
        }
        .navbar-brand {
            font-weight: bold;
        }
        .sidebar {
            min-height: calc(100vh - 56px);
            background-color: #f8f9fa;
            padding-top: 20px;
        }
        .sidebar .nav-link {
            color: #333;
            padding: 0.5rem 1rem;
            margin-bottom: 5px;
        }
        .sidebar .nav-link:hover {
            background-color: #e9ecef;
        }
        .sidebar .nav-link.active {
            background-color: #0d6efd;
            color: white;
        }
        .sidebar .nav-link i {
            margin-right: 10px;
        }
        .card {
            margin-bottom: 20px;
            box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
        }
        .footer {
            background-color: #f8f9fa;
            padding: 1rem 0;
            margin-top: auto;
        }
        .alert-container {
            position: fixed;
            top: 70px;
            right: 20px;
            z-index: 1050;
            max-width: 300px;
        }
    </style>
    {% block extra_css %}{% endblock %}
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <div class="container">
            <a class="navbar-brand" href="{{ url_for('index') }}">
                <i class="fas fa-cubes me-2"></i>区块链分析系统
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav ms-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('index') }}">
                            <i class="fas fa-home"></i> 首页
                        </a>
                    </li>
                    {% if session.get('user_id') %}
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('dashboard') }}">
                            <i class="fas fa-tachometer-alt"></i> 仪表盘
                        </a>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown">
                            <i class="fas fa-user"></i> {{ session.get('username') }}
                        </a>
                        <ul class="dropdown-menu dropdown-menu-end">
                            <li><a class="dropdown-item" href="{{ url_for('profile') }}"><i class="fas fa-id-card me-2"></i>个人信息</a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item" href="{{ url_for('logout') }}"><i class="fas fa-sign-out-alt me-2"></i>退出登录</a></li>
                        </ul>
                    </li>
                    {% else %}
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('login') }}">
                            <i class="fas fa-sign-in-alt"></i> 登录
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('register') }}">
                            <i class="fas fa-user-plus"></i> 注册
                        </a>
                    </li>
                    {% endif %}
                </ul>
            </div>
        </div>
    </nav>

    <!-- 内容区域 -->
    <div class="content">
        {% if session.get('user_id') %}
        <div class="container-fluid">
            <div class="row">
                <!-- 侧边栏 -->
                <div class="col-md-3 col-lg-2 d-md-block sidebar collapse">
                    <div class="position-sticky">
                        <ul class="nav flex-column">
                            <li class="nav-item">
                                <a class="nav-link {% if request.path == url_for('dashboard') %}active{% endif %}" href="{{ url_for('dashboard') }}">
                                    <i class="fas fa-tachometer-alt"></i> 仪表盘
                                </a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link {% if request.path == url_for('transactions') %}active{% endif %}" href="{{ url_for('transactions') }}">
                                    <i class="fas fa-exchange-alt"></i> 交易数据明细
                                </a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link {% if request.path == url_for('import_data_page') %}active{% endif %}" href="{{ url_for('import_data_page') }}">
                                    <i class="fas fa-file-import"></i> 数据导入
                                </a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link {% if request.path == url_for('transaction_summary') %}active{% endif %}" href="{{ url_for('transaction_summary') }}">
                                    <i class="fas fa-chart-pie"></i> 交易数据汇总
                                </a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link {% if request.path == url_for('visualization') %}active{% endif %}" href="{{ url_for('visualization') }}">
                                    <i class="fas fa-chart-bar"></i> 数据可视化
                                </a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link {% if request.path == url_for('fraud_detection') %}active{% endif %}" href="{{ url_for('fraud_detection') }}">
                                    <i class="fas fa-shield-alt"></i> 非法账号识别
                                </a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link {% if request.path == url_for('profile') %}active{% endif %}" href="{{ url_for('profile') }}">
                                    <i class="fas fa-user-cog"></i> 个人信息
                                </a>
                            </li>
                        </ul>
                    </div>
                </div>
                
                <!-- 主内容区 -->
                <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4 py-4">
                    <!-- 消息提示 -->
                    <div class="alert-container">
                        {% with messages = get_flashed_messages(with_categories=true) %}
                            {% if messages %}
                                {% for category, message in messages %}
                                    <div class="alert alert-{{ category }} alert-dismissible fade show">
                                        {{ message }}
                                        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                                    </div>
                                {% endfor %}
                            {% endif %}
                        {% endwith %}
                    </div>
                    
                    {% block content %}{% endblock %}
                </main>
            </div>
        </div>
        {% else %}
        <div class="container py-4">
            <!-- 消息提示 -->
            <div class="alert-container">
                {% with messages = get_flashed_messages(with_categories=true) %}
                    {% if messages %}
                        {% for category, message in messages %}
                            <div class="alert alert-{{ category }} alert-dismissible fade show">
                                {{ message }}
                                <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                            </div>
                        {% endfor %}
                    {% endif %}
                {% endwith %}
            </div>
            
            {% block content_no_sidebar %}{% endblock %}
        </div>
        {% endif %}
    </div>

    <!-- 页脚 -->
    <footer class="footer text-center">
        <div class="container">
            <span class="text-muted">© 2025 区块链交易行为特征分析与可视化系统</span>
        </div>
    </footer>

    <!-- Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <!-- 自动关闭警告框 -->
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 3秒后自动关闭警告框
            setTimeout(function() {
                var alerts = document.querySelectorAll('.alert');
                alerts.forEach(function(alert) {
                    var bsAlert = new bootstrap.Alert(alert);
                    bsAlert.close();
                });
            }, 3000);
        });
    </script>
    {% block extra_js %}{% endblock %}
</body>
</html>